﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Master_Login : BasePage
{
    protected string ErrMsg { get { return base.QueryString("errmsg"); } }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
        }
        if (!string.IsNullOrEmpty(ErrMsg))//提示
        {
            Alert(ErrMsg);
        }
        if (Request["logout"] != null)//注销登陆
        {
            ManagerFactory.UserManagerManager.SignOut();
            Response.Redirect("~/");
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (IsValid) {
            if (Session["__ValidationCode"] != null)
            {
                if (txtCode.Text.ToLower() != Session["__ValidationCode"].ToString().ToLower())
                {
                    Alert("验证码错误！");
                    return;
                }
            }
            string strMsg = "用户名或者密码错误";
            if (ManagerFactory.UserManagerManager.Authenticate(UserNameTextBox.Text.Trim(), UserPassTextBox.Text.Trim(), true))
            {
                Response.Redirect("~/Master/Default.aspx");
                //System.Web.UI.ScriptManager.RegisterStartupScript(Page, Page.GetType(), "aaaa", "<script language ='javascript'>OpenScreenWindow('DefaultMain.aspx')</script>", false);
            }
            else
            {
                Alert(strMsg);
            }

        }
    }
}
